<?php
namespace App\Http\Controllers;

use App\Http\Model\Hint;
use App\Http\Services\ChatFriendServices;
use App\Http\Services\UserServices;
use App\Http\Services\UserTagServices;
use Illuminate\Http\Request;
use App\Lib\Response;
use Carbon\Carbon;
use Illuminate\Support\Facades\Redis;

class ChatFriendsController extends Controller
{
    private $services_users;
    protected $chatFriendService;
    protected $userTagService;


    public function __construct()
    {
        $this->services_users = new UserServices();//用户服务
        $this->chatFriendService = new ChatFriendServices();//交友聊天
        $this->userTagService = new UserTagServices();//用户标签服务
    }

    //交友大厅显示
    public function checkUserBaseInfo(Request $request){
        //获取用户基本信息
        $userInfo = $this->services_users->get_current_user();
        if(empty($userInfo))
        {
            Response::returnResult(Hint::ERR_USER_LOGIN_STATUS);  
        }
        //获取主播个人资料
        $res = $this->chatFriendService->checkUserBaseInfo($userInfo);
        Response::returnResult(Hint::SUCCESS,$res['data']);
    }

    //获取我的资料详情信息
    public function myBaseInfo(Request $request){
        //我的资料详情
        $myInfo = $this->services_users->get_current_user();
        if(empty($myInfo))
        {
            Response::returnResult(Hint::ERR_USER_LOGIN_STATUS);  
        }
        //获取审核状态
        $verify = $this->chatFriendService->getVerify($myInfo['user_id']);
        $data['status'] = 0; //审核中
        if(!empty($verify)){
            $data['status'] = $verify['status'];
            $myInfo['chat_sign'] = $verify['chat_sign'];
        }
        //整理数据
        $tagList = [];
        if(!empty($myInfo['tags'])){
            $tagInfo = $this->userTagService->getTagNames($myInfo['tags']);
            foreach($tagInfo as $k=>$v){
                $tagList[] = ['name'=>$v,'tag_id'=>$k];
            }
        }
        $myInfo['tags'] = $tagList;
        
        $data['myinfo'] = $myInfo;
        Response::returnResult(Hint::SUCCESS,$data);
    }

    //根据不同身份展示不同用户列表
    public function getListData(Request $request){
        $page = $request->get('page',1);
        $limit = $request->get('limit',20);
        //获取用户基本信息
        $userInfo = $this->services_users->get_current_user();
        if(empty($userInfo))
        {
            Response::returnResult(Hint::ERR_USER_LOGIN_STATUS);
        }
        //查看是否是主播若是后主播则显示用户列表
        $list = $this->chatFriendService->getListData($page,$limit,$userInfo['user_id']);

        if($list['code'] != 0){
            Response::returnResult(Hint::ERR_NORMAL,[],$list['msg']);
        }
        Response::returnResult(Hint::SUCCESS,$list['list']);
    }

//    public function getListData2(Request $request){
//        $page = $request->get('page',1);
//        $limit = $request->get('limit',20);
//        $userInfo['user_id']=10010;
//
//        //获取用户基本信息
////        $userInfo = $this->services_users->get_current_user();
////        if(empty($userInfo))
////        {
////            Response::returnResult(Hint::ERR_USER_LOGIN_STATUS);
////        }
//        //查看是否是主播若是后主播则显示用户列表
//        $list = $this->chatFriendService->getListData2($page,$limit,$userInfo['user_id']);
//
//        if($list['code'] != 0){
//            Response::returnResult(Hint::ERR_NORMAL,[],$list['msg']);
//        }
//        Response::returnResult(Hint::SUCCESS,$list['list']);
//    }
}